from django.template import Library
from django.urls import reverse, resolve  # py中反向解析url地址

from web import models

register = Library()


@register.inclusion_tag('inclusion/all_project_list.html')
def all_project_list(request):
    # 获取我创建的项目
    # my_project_list = models.Project.objects.filter(creator='当前登录用户')
    my_project_list = models.Project.objects.filter(creator=request.bug_platform.user)
    # 获取我参与的项目
    join_project_list = models.ProjectUser.objects.filter(user=request.bug_platform.user)

    return {'my': my_project_list, 'join': join_project_list, 'request': request}


@register.inclusion_tag('inclusion/manage_menu_list.html')
def manage_menu_list(request):
    data_list = [
        {'title': '概览', 'url': reverse('dashboard', kwargs={'project_id=': request.bug_platform.project.id})},
        {'title': '问题', 'url': reverse('issues', kwargs={'project_id=': request.bug_platform.project.id})},
        {'title': '统计', 'url': reverse('statistics', kwargs={'project_id=': request.bug_platform.project.id})},
        {'title': 'wiki', 'url': reverse('wiki', kwargs={'project_id=': request.bug_platform.project.id})},
        {'title': '文件', 'url': reverse('file', kwargs={'project_id=': request.bug_platform.project.id})},
        {'title': '配置', 'url': reverse('setting', kwargs={'project_id=': request.bug_platform.project.id})},
    ]

    return {'data_list': data_list}
